package com.rfsp.mcp.service;


import com.rfsp.common.base.BaseService;
import com.rfsp.mcp.mapper.CustOrgTypeMapper;
import com.rfsp.mcp.mapper.OrgTypeMapper;
import com.rfsp.mcp.pojo.po.CustOrgTypePO;
import com.rfsp.common.pojo.po.DictPO;
import com.rfsp.mcp.pojo.po.OrgTypePO;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrgTypeService extends BaseService<DictPO> {

	public Logger log = LoggerFactory.getLogger(OrgTypeService.class);
	
	
	@Autowired
	OrgTypeMapper mapper;
	
	@Autowired
    CustOrgTypeMapper custOrgTypeMapper;
	
	public OrgTypePO get(String orgCode){
		return mapper.getOne(orgCode);
	}
	public String getTypeName(String orgCode){
		
		if(orgCode==null){
			return "";
		}
		
		String enterpriseType = "";
        CustOrgTypePO custOrgTypePO = null;
        if(StringUtils.isNotBlank(orgCode)) {
        	if(orgCode.length() == 2) {
            	custOrgTypePO = custOrgTypeMapper.get(orgCode);
            	if(custOrgTypePO != null) {
            		enterpriseType = custOrgTypePO.getOrgname();
            	}
            }else {
            	String orgType1 = "";
            	String orgType2 = "";
            	custOrgTypePO = custOrgTypeMapper.get(orgCode.substring(0, 2));
            	if(custOrgTypePO != null) {
            		orgType1 = custOrgTypePO.getOrgname();
            		
            		custOrgTypePO = custOrgTypeMapper.get(orgCode);
            		if(custOrgTypePO != null) {
                		orgType2 = custOrgTypePO.getOrgname();
                		enterpriseType = orgType1 + "-" +orgType2;
            		}
            	}
            }
        }
		return enterpriseType;
	}
}
